import * as echarts from 'echarts';
import { useEffect, useRef } from 'react';
import { getDataReports } from "../../api/goods";
import option from './options';
function Reports(){
    let boxRef:{current:any} = useRef();
    let getData =async ()=>{
        let res:ResponsType= await getDataReports();
        console.log(res.data.data)
        option.xAxis = res.data.data.xAxis;
        option.yAxis = res.data.data.yAxis;
        option.legend = res.data.data.legend;
        option.series = res.data.data.series;
         //初始化echarts
     let boxEcharts =   echarts.init(boxRef.current);
     console.log(boxEcharts)
     //  配置echarts
      boxEcharts.setOption(option)
    //   echarts适配
     window.onresize = ()=>{
        boxEcharts.resize();
     }
    }
    useEffect(()=>{
      getData();
      return ()=>{
        window.onresize = null;
      }
    },[])
    
    return (
        <div>
            <div style={{width:"100%",height:"500px"}} ref ={boxRef}>

            </div>
        </div>
    )
}

export default Reports;